//
//  Singleton.m
//  RoadLine
//
//  Created by dllo on 15/4/25.
//  Copyright (c) 2015年 RedFireNoodles. All rights reserved.
//

#import "Singleton.h"

@implementation Singleton

+(instancetype)shareSingleton{

    static Singleton *single = nil;
    static dispatch_once_t oneToTake;
    dispatch_once(&oneToTake, ^{
    
        single = [[Singleton alloc] init];
    });
    return single;

}

-(void)setIsNight:(BOOL)isNight{
    _isNight = isNight;
    if (isNight) {
        //为NightDayNSNotification注册
        [[NSNotificationCenter defaultCenter] postNotificationName:@"NightDayNSNotification" object:nil];
    }else{
        [[NSNotificationCenter defaultCenter] postNotificationName:@"LightDayNSNotification" object:nil];
    }
}

//将各种数据存储到NSUserDefautls中
-(void)saveNightModeInfoToDisk{
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSString *isNightStr = nil;
    if (self.isNight) {
        isNightStr = @"yes";
    }else{
        isNightStr = @"no";
    }
    [user setObject:isNightStr forKey:@"isNight"];
    
    //这里建议同步存储到磁盘中，但是不是必须的
    [user synchronize];
}

//从NSUserDefautls中读取各种数据
-(void)loadNightModeInfoFormDisk{
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    
    NSString *isNightStr = [user objectForKey:@"isNight"];
    self.isNight = [isNightStr isEqualToString:@"yes"];
}


@end
